package com.example.gfsquadwebviewproject.dialog.update;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;

import com.example.gfsquadwebviewproject.util.L;

public class UpdateDialogBuilder {
    String TAG = "UpdateDialogBuilder";

    UpdateDialog updateDialog = null ;
    WindowManager.LayoutParams lp;
    Window dialogWindow = null;

    public UpdateDialog buildDialog(Context context){
        try {
            if (updateDialog != null) {
                updateDialog = null;
            }
            updateDialog = new UpdateDialog(context);//对话框
            if (dialogWindow == null) {
                dialogWindow = updateDialog.getWindow();
                DisplayMetrics dm2 = context.getResources().getDisplayMetrics();
                int width = dm2.widthPixels;
                int height = dm2.heightPixels;
                lp = dialogWindow.getAttributes();
                dialogWindow.setGravity(Gravity.LEFT | Gravity.TOP);
                lp.width = (int) (width * 0.42); // 宽度
                lp.height = (int) (height * 0.28); // 高度
                lp.x = (width - lp.width) / 2; // 新位置X坐标
                lp.y = (height - lp.height) / 2 - lp.height / 15; // 新位置Y坐标
                lp.alpha = 1.0f; // 透明度
                dialogWindow.setAttributes(lp);
            }
        }
        catch (Exception e){
            L.wf(TAG,"buildDialog error:"+e);
        }
        return updateDialog;
    }

}
